/*
 * @Author: c
 * @Date: 2024-01-12 18:30:00
 * @LastEditTime: 2024-01-29 08:52:30
 * @LastEditors: c
 * @Description: 
 * @FilePath: \music-web-backend\src\core\music\rate_file_info\entity\audio.enity.ts
 * https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// Copyright 2024 Administrator
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { Song } from "src/core/music/song/entities/song.entity";
import { FileInfo } from "src/core/system/minio/entities/file_info.entity";
import { Column, Entity, JoinColumn, ManyToOne, OneToOne, PrimaryGeneratedColumn } from "typeorm";
import { AudioRateEnum } from "../../../../common/enums/audio.enum";

export enum FileDurationType { 'FULL', 'CUT' }

@Entity({
    name: 'rate_file_info',
})
export class RateFileInfo {

    @PrimaryGeneratedColumn()
    id: number;

    //音频质量
    @Column({
        name: 'rate',
        type: 'enum',
        enum: AudioRateEnum,
        default: AudioRateEnum.UNDAMAGED //默认无损
    })
    rate: AudioRateEnum;

    //资源的size大小
    @Column({
        name: 'size',
        type: 'decimal',
        comment: '资源的size大小'
    })
    size: number;

    //资源的格式
    @Column({
        name: "format",
        type: "varchar",
        comment: "资源的格式"
    })
    format: string;

    //歌曲时长
    @Column({
        name: "start_time",
        type: 'int',
        default: 0,
        comment: '歌曲记录开始时间'
    })
    startTime: number;

    //歌曲过期时间
    @Column({
        name: "expired_time",
        type: 'int',
        default: 2 * 60 * 60,
        comment: '歌曲过期时间'
    })
    expiredTime: number;

    //歌曲时长
    @Column({
        name: "duration",
        type: 'decimal',
        comment: '歌曲时长'
    })
    duration: number;

    //是否是完整的
    @Column({
        name: 'is_full',
        type: 'boolean',
        default: true,
        comment: "是否是试听版本"
    })
    isFull: boolean

    //关联的音频id
    @ManyToOne(() => Song, (song) => song.rateFileInfos, {
        onDelete: 'CASCADE' //根据songid外键级联删除audioinfo
    })
    @JoinColumn({
        name: "song_id"
    })
    song: Song;


    //关联的文件id
    @OneToOne(() => FileInfo, fileInfo => fileInfo.rateFileInfo,
        {
            eager: true,
            cascade: true,
            onDelete: 'CASCADE' //级联删除关联的fileinfo
        }
    )
    // @JoinColumn({
    //     name: 'file_id',
    //     referencedColumnName: "id",
    // })
    fileInfo: FileInfo;
}